// test2解析

const MyPromise = require('./MyPromise')

let p1 = MyPromise.resolve()
let p3 = p1.then(() => {
    console.log(0);
    let p2 = MyPromise.resolve(4)
    return p2
})
p3.then(res => {
    console.log(res);
})

let p4 = MyPromise.resolve()
let p5 = p4.then(() => {
    console.log(1);
})
let p6 = p5.then(() => {
    console.log(2);
})
let p7 = p6.then(() => {
    console.log(3);
})
let p8 = p7.then(() => {
    console.log(5);
})
let p9 = p8.then(() => {
    console.log(6);
})


/**
关键1：onFulfilled如果返回一个promise，那么就会调用newPromiseResolveThenableJobTask生成一个promiseResolveThenableJobTask，这也是一个微任务
关键2：promiseResolveThenableJobTask的内容则是Promise.resolve(4).then(res=>ReslovePromise(res))，再生成一个微任务
等两个微任务执行完之后res => console.log(res)才会进入microtask，所以中间多了两个微任务

过程展示
microtask                                              output
[p1.onFulfilled, p4.onFulfilled]
[p4.onFulfilled, promiseResolveThenableJobTask(p2)]    0
[promiseResolveThenableJobTask(p2), p5.onFulfilled]    1
[p5.onFulfilled, p2.onFulfilled]
[p2.onFulfilled, p6.onFulfilled]                       2                    
[p6.onFulfilled, p3.onFulfilled,p7.onFulfilled]        
[p3.onFulfilled,p7.onFulfilled,p8.onFulfilled]         3    
[p7.onFulfilled,p8.onFulfilled]                        4       
[p8.onFulfilled]                                       5    
[]                                                     6        
 */